<%@ page import="com.yinhai.core.common.api.config.impl.SysConfig"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<jsp:directive.page import="java.util.Date" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<%@ taglib prefix="ta" tagdir="/WEB-INF/tags/tatags"%>

<html xmlns="http://www.w3.org/1999/xhtml" style="height:100%">
<head>
<title>电子邮件配置</title>
</head>
<%@ include file="/ta/inc.jsp"%>
<body >
	<ta:pageloading />
		<ta:panel id="pnl_frm" key="基本信息" >
			<ta:form id="form1" >
				<ta:text id="emailAddress" key="邮箱账号" columnWidth="0.8" required="true" validType="email" textHelp="您所要代理的邮箱账号" onChange="fnEmailChange(this)"/>
				<!-- onFocus事件禁止浏览器自动填充表单 -->
				<ta:text id="password" onFocus="this.type='password'" key="密码或授权码" type="text" required="true" textHelp="有的邮箱需要设置开启SMTP/POP/IMAP服务并获取授权码" columnWidth="0.8"/>
				<ta:box cols="2">
					<ta:text id="sendHost" key="发送服务器主机名" cssStyle="margin-right:20px" required="true" textHelp="可从邮件服务商处获取" columnWidth="0.7"/>
					<ta:number id="sendPort" required="true"  value="25" key="端口" min="0" max="65536" cssStyle="margin-left:-50px" columnWidth="0.3"/>
				</ta:box>
				<ta:box cols="5">
					<ta:text id="timeout" cssStyle="margin-right:20px" key="超时时间" value="30000" required="true" textHelp="设置发送邮件的超时时间，超过此时间显示发送失败信息，1秒等于1000毫秒" span="2"/>
					<ta:box cssStyle="padding-top:8px" >毫秒</ta:box>
				</ta:box>
				<ta:box cssStyle="margin-left:100px" >
					<ta:checkboxgroup cols="3" >
						<ta:checkbox key="默认邮箱" id="defaultemail" value="dm" />
						<ta:checkbox id="isSendSSL" key="使用SSL发送" value="ssl" onClick="fnSSL()"/>
						<ta:checkbox id="isSendTLS" key="使用TLS发送" value="tls" onClick="fnTLS()"/>
					</ta:checkboxgroup>
				</ta:box>
			</ta:form>
		</ta:panel>
		<ta:box cols="3" fit="true" >
			<ta:panel id="centerLeft" key="未分配接入系统" fit="true" columnWidth="0.43">
				<ta:datagrid id="unDistrbutedSystem" fit="true"  selectType="checkbox" forceFitColumns="true" >
					<ta:datagridItem id="id" hiddenColumn="true"></ta:datagridItem>
					<ta:datagridItem id="systemid" key="系统ID"></ta:datagridItem>
					<ta:datagridItem id="systemname" key="系统名称" ></ta:datagridItem>
				</ta:datagrid>
			</ta:panel>
			<ta:box  columnWidth="0.14" cssStyle="margin-left:10px;margin-top:80px">
				<div style="width:100%;position: relative;" id="centerdiv">
					<ta:button key="增加" cssStyle="display:block;margin:0 auto" icon="xui-icon-next" isShowIcon="true" onClick="batchAddSystem()"/>
					<ta:button key="移除" cssStyle="display:block;margin:0 auto;margin-top:10px;" icon="xui-icon-back" isShowIcon="true" onClick="batchDeleteSystem()"/>
					<ta:button id="btn_save" key="保存" cssStyle="display:block;margin:0 auto;margin-top:30px;" isok="true" isShowIcon="true" onClick="save()"/>
					<ta:button id="btn_cancel" key="取消" cssStyle="display:block;margin:0 auto;margin-top:10px;" hotKey="C" onClick="parent.Base.closeWindow('addconfig')" />
				</div>
			</ta:box>
			<ta:panel id="centerRight" key="已分配到当前邮箱的接入系统" fit="true" cssStyle="margin-left:10px;"  columnWidth="0.43">
				<ta:datagrid id="distrbutedSystem" fit="true" forceFitColumns="true" selectType="checkbox">
					<ta:datagridItem id="id" hiddenColumn="true"></ta:datagridItem>
					<ta:datagridItem id="systemid" key="系统ID"></ta:datagridItem>
					<ta:datagridItem id="systemname" key="系统名称" ></ta:datagridItem>
				</ta:datagrid>
			</ta:panel>
		</ta:box>
</body>
</html>
<script type="text/javascript">
	/* 当前被选择的行 */
	var currentRow = null;
	
	$(document).ready(function() {
		$("body").taLayout();
	});
	
	/*邮箱账户改变事件*/
	function fnEmailChange(obj){
		Base.submit("emailAddress","EmailConfigController!checkemailAddress.do");
		var server = obj.value;
		var serverSuffix = server.split('@')[1];
		if(serverSuffix){
			Base.setValue("sendHost","smtp"+"."+serverSuffix);
		}else{
			Base.setValue("sendHost","");
		}
	}
	
	/*设置SSL协议*/
	function fnSSL(){
		/*根据接发送SSL复选框的值进行设定*/
		var status = Base.getValue("isSendSSL");
		if(status==null){
			Base.setValue("sendPort","25");
		}else{
			Base.setValue("sendPort","465");
			Base.setValue("isSendTLS",null);
		}
	}
	
	/*设置TLS协议*/
	function fnTLS(){
		/*根据接发送TLS复选框的值进行设定*/
		var status = Base.getValue("isSendTLS");
		if(status!=null&&status=="tls"){
			Base.setValue("sendPort","25");
			Base.setValue("isSendSSL",null);
		}
	}
	
	/*保存数据*/
	function save(){
		var valid = Base.validateForm("form1");
		if(valid){
			Base.setDisabled("btn_save");
			Base.checkedAllData("distrbutedSystem");
			Base.submit('form1,distrbutedSystem','EmailConfigController!addEmailConfig.do',null,null,null,function(){
				parent.Base.submit("pnlEmailQry,MainGrid","EmailConfigController!pageQueryEmailConfig.do")});
		}
	}
	
	//增加接入系统 
	function batchAddSystem(){
		var sysSelect = Base.getGridSelectedRows("unDistrbutedSystem");
		var sysAll = Base.getGridData("unDistrbutedSystem");
		var otherAll = Base.getGridData("distrbutedSystem");
		if(sysSelect && sysSelect.length > 0 ){
			var s = Ta.util.obj2string(sysSelect);
			var all = Ta.util.obj2string(sysAll);
			var otherAll = Ta.util.obj2string(otherAll);
			Base.submit('','EmailConfigController!batchAddSystem.do',{"dto['selected']":s,"dto['all']":all,"dto['otherAll']":otherAll},null,null);
		}else{
			Base.alert("请勾选要使用此邮箱的接入系统!","warn");
		}
	}
	
	/* 批量移除接入系统 */
	function batchDeleteSystem(){
		var sysSelect = Base.getGridSelectedRows("distrbutedSystem");
		var sysAll = Base.getGridData("distrbutedSystem");
		var otherAll = Base.getGridData("unDistrbutedSystem");
		if(sysSelect && sysSelect.length > 0 ){
			var s = Ta.util.obj2string(sysSelect);
			var all = Ta.util.obj2string(sysAll);
			var otherAll = Ta.util.obj2string(otherAll);
			Base.submit('','EmailConfigController!batchDeleteSystem.do',{"dto['selected']":s,"dto['all']":all,"dto['otherAll']":otherAll},null,null);
		}else{
			Base.alert("请勾选要移出此邮箱的接入系统!","warn");
		}
	} 
	
</script>
<%@ include file="/ta/incfooter.jsp"%>